package python

import (
	"awesomeTask/application/models/project"
	"awesomeTask/system/http"
)

type ProjectHandler struct {
	http.HttpBaseHandler
}

func (handler *ProjectHandler) GetModuleName() string {
	return "/programe/project/"
}
func (handler *ProjectHandler) ActionCreate() interface{} {
	id := handler.PostOne("id")
	projectName := handler.PostOne("project_name").(string)
	description := handler.PostOne("description").(string)
	uid := handler.getUserInfo()["id"].(string)
	groupId := handler.getUserInfo()["gid"].(string)

	if project.CreateProject(projectName, description, id, groupId, uid) {
		return map[string]interface{}{
			"msg": "创建成功,集群环境将在后台自动构建",
		}
	} else {
		return map[string]interface{}{
			"msg": "创建失败",
		}
	}
}

func (handler *ProjectHandler) getUserInfo() map[string]interface{} {
	return map[string]interface{}{
		"id":  "1",
		"gid": "1",
	}
}

func (handler *ProjectHandler) ActionIndex() interface{} {
	return map[string]interface{}{
		"list": project.GetProject(handler.getUserInfo()["id"].(string)),
	}
}
